package com.egoo.ticket.server.config.mq;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;

/**
 * @Auther: victor_tang
 * @Date: 2020/8/9 14:17
 * @Description: rabbitmq配置类
 */
@SpringBootConfiguration
public class RabbitMqConfig {
    /*********************************工作模式队列名*********************************/
    // 触发器队列
    public String WORKORDER_TRIGGER;
    // 系统消息队列
    public String WORKORDER_SYSMSG;
    // 短信队列
    public String WORKORDER_SHORTMSG;
    //通用队列
	public String WORKORDER_GENERAL;
    //同步内管数据队列
	public String WORKORDER_SYNEURMDATA;

    @Value("${spring.profiles.active}")
    public void setInfoValue(String active) {
        WORKORDER_TRIGGER = "workorder_trigger" +"_"+ active;
        WORKORDER_SYSMSG = "workorder_sysmsg" +"_"+ active;
        WORKORDER_SHORTMSG = "workorder_shortmsg" +"_"+ active;
		WORKORDER_GENERAL = "workorder_general" + "_"+ active;
		WORKORDER_SYNEURMDATA = "workorder_syneurmdata" + "_"+ active;
    }

    /*****************************工作模型*****************************/
    /**
     * TODO 初始化队列
     * @author: victor_tang
     * @createtime: 2020/8/27 18:32
     * @param
     * @return: org.springframework.amqp.core.Queue
     */
    @Bean
    public Queue triggerQueue() {
        return new Queue(WORKORDER_TRIGGER, true);
    }
    @Bean
    public Queue sysMsgQueue() {
        return new Queue(WORKORDER_SYSMSG, true);
    }
    @Bean
    public Queue shortMsgQueue() {
        return new Queue(WORKORDER_SHORTMSG, true);
    }
	@Bean
	public Queue generalQueue() {
		return new Queue(WORKORDER_GENERAL, true);
	}
	@Bean
	public Queue syneurmdataQueue() {
		return new Queue(WORKORDER_SYNEURMDATA, true);
	}

    /*************以下为预留两种exchange模式，暂注释，待业务场景需要时再放开***********/
//    //发布订阅交换机
//    public static String EXCHANGE_FANOUT = "exchange_fanout";
//    public static String QUEUE_FANOUT1 = "queue_fanout1";
//    public static String QUEUE_FANOUT2 = "queue_fanout2";
//
//    //topic交换机
//    public static String EXCHANGE_TOPIC = "exchange_topic";
//    public static String QUEUE_TOPIC1 = "queue_topic1";
//    public static String QUEUE_TOPIC2 = "queue_topic2";
//
//    public static String ROUTING_KEY = "topic";
//    /**********************Fanout exchange模型*****************************/
//    // 准备交换机
//    @Bean
//    public FanoutExchange exchangeFanout() {
//        return new FanoutExchange(EXCHANGE_FANOUT);
//    }
//    // 创建队列
//    @Bean
//    public Queue queueFanout1() {
//        return new Queue(QUEUE_FANOUT1);
//    }
//    @Bean
//    public Queue queueFanout2() {
//        return new Queue(QUEUE_FANOUT2);
//    }
//    // 将交换机和队列进行绑定
//    @Bean
//    public Binding bindingExchange1() {
//        return BindingBuilder.bind(queueFanout1()).to(exchangeFanout());
//    }
//    @Bean
//    public Binding bindingExchange2() {
//        return BindingBuilder.bind(queueFanout2()).to(exchangeFanout());
//    }
//
//
//    /**********************topic exchange模型*****************************/
//    @Bean
//    public TopicExchange exchangeTopic() {
//        return new TopicExchange(EXCHANGE_TOPIC);
//    }
//    @Bean
//    public Queue queueTopic1() {
//        return new Queue(QUEUE_TOPIC1);
//    }
//    @Bean
//    public Queue queueTopic2() {
//        return new Queue(QUEUE_TOPIC2);
//    }
//
//    /**
//     * 根据路由关键字模糊匹配队列，
//     * #模糊匹配多级路径，利于 topic.#  即可匹配topic.aaa，也可匹配topic.aaa.bbb
//     * *模糊匹配单级别topic.*    只可匹配topic.aaa
//     */
//    @Bean
//    public Binding bindingTopic1() {
//        return BindingBuilder.bind(queueTopic1()).to(exchangeTopic()).with(ROUTING_KEY+".#");
//    }
//    @Bean
//    public Binding bindingTopic2() {
//        return BindingBuilder.bind(queueTopic2()).to(exchangeTopic()).with(ROUTING_KEY+".*");
//    }


}

